<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>

    <style>
        .font_size_hui {
            color: #a6a6a6;
        }

        #nav ul {
            list-style: none;

        }

        #nav li {
            display: inline;

        }

        #csdn-copyright-footer.side .copyright-footer-middle {
            padding: 12px 0;
            border-top: 1px solid #f3f3f3;
            border-bottom: 1px solid #f3f3f3;
            display: -webkit-box;
            display: -ms-flexbox;
            display: flex;
            -webkit-box-pack: justify;
            -ms-flex-pack: justify;
            justify-content: space-between;
        }

    </style>

</head>
<body>
<nav class="navbar navbar-default .navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">七仔家园</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">博客 <span class="sr-only">(current)</span></a></li>

                <!--打印分类和标签-->
                {% for category_obj in category_list %}
                     <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false" username="{{ category_obj.name }} ">{{ category_obj.name }} <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        {% for tag_obj  in category_obj.tag_set.all %}
                            <li><a href="?tag_username={{ tag_obj.name }}" username="{{ tag_obj.name }}">{{ tag_obj.name }}</a></li>
                        {% endfor %}
                    </ul>
                </li>
                {% endfor %}

            <li><a href="#">学堂</a></li>
            </ul>
            <!--<form class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Search">
                </div>
                <button type="submit" class="btn btn-default">搜索</button>
            </form>-->
            <ul class="nav navbar-nav navbar-right">
                {% if request.user.is_authenticated %}
                    <li><a href="/mysite/{{ request.user.username }}/">{{ request.user.username }}</a></li>
                    <li><a href="/mysite/publish/article/">发布</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                           aria-expanded="false">更多操作 <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#" data-toggle="modal" data-target=".bs-example-modal-lg">修改密码</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="/user/logout/">退出登录</a></li>
                        </ul>
                    </li>
                    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog"
                         aria-labelledby="myLargeModalLabel">
                        <div class="modal-dialog modal-lg" role="document">
                            <div class="modal-content">
                                <div class="container-fluid">
                                    <div class="row">
                                        <div class="col-md-8 col-md-offset-2">
                                            <h2 class="text-center">修改密码</h2>
                                            <div class="form-group">
                                                <label for="">用户名:</label>
                                                <input type="text" class="form-control" value="{{ request.user.username }}" disabled>
                                            </div>
                                            <div class="form-group">
                                                <label for="old_password">原密码:</label>
                                                <input type="password" class="form-control" id="old_password"
                                                       username="old_password">
                                            </div>
                                            <div class="form-group">
                                                <label for="new_password">新密码:</label>
                                                <input type="password" class="form-control" id="new_password"
                                                       username="new_password">
                                            </div>
                                            <div class="form-group">
                                                <label for="confirm_password">原密码:</label>
                                                <input type="password" class="form-control" id="confirm_password"
                                                       username="confirm_password">
                                            </div>
                                            <br>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">
                                                    取消
                                                </button>
                                                <button type="button" class="btn btn-primary" id="id_commit">保存</button>
                                                <span style="color: red" id="error"></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                {% else %}
                    <li><a href="/user/register/">注册</a></li>
                    <li><a href="/user/login/">登录</a></li>
                {% endif %}
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
<br>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-9">
            <ul class="media-list">
                {% for article_obj in page_queryset %}
                    <li>
                        <div class="media">
                            <h4 class="media-heading"><a
                                    href="/home/{{ article_obj.blog.user.username }}/article/{{ article_obj.id }}/">{{ article_obj.title }}</a>
                            </h4>
                            <br>
                            <div class="media-left media-middle">
                                <a href="#">
                                    <img class="media-object" src="/media/{{ article_obj.blog.user.avatar }}" alt="..."
                                         width="50">
                                </a>
                            </div>
                            <div class="media-body">
                                {{ article_obj.desc }}
                            </div>
                        </div>
                    </li>
                    <br>
                    <div>
                        <span>
                            <a href="/mysite/{{ article_obj.blog.user.username }}/">{{ article_obj.blog.user.username }}</a>&nbsp;&nbsp;
                        </span>
                        <span>发布于</span>
                        <span>{{ article_obj.create_time|date:'Y-m-d' }}&nbsp;&nbsp;</span>
                        <span><span class="glyphicon glyphicon-comment"></span>评论({{ article_obj.comment_num }})&nbsp;&nbsp;</span>
                        <span><span class="glyphicon glyphicon-thumbs-up"></span>点赞({{ article_obj.up_num }})&nbsp;&nbsp;</span>
                        <span><span class="glyphicon glyphicon-thumbs-down"></span>点踩({{ article_obj.down_num }})</span>
                    </div>
                    <hr>
                {% endfor %}
                {{ page_obj.page_html|safe }}
            </ul>
        </div>
        <div class="col-md-3">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title text-center">最新发布文章</h3>
                </div>
                <div class="panel-body">
                    {% for recent_article_obj in recent_article_list %}
                        {{ forloop.counter }}  <a href="/home/{{ recent_article_obj.blog.user.username }}/article/{{ recent_article_obj.id }}/">{{ recent_article_obj.title }}</a>
                        <br>
                        <br>
                    {% endfor %}
                </div>
            </div>

            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title text-center">阅读排行榜</h3>
                </div>
                <div class="panel-body">
                    {% for article in top_article_obj %}
                        {{ forloop.counter }}  <a href="/home/{{ article.blog.user.username }}/article/{{ article.id }}">{{ article.title }}</a>
                        &nbsp;<span class="glyphicon glyphicon-eye-open" style="color: #adadad">&nbsp{{ article.visitor_num }}</span>
                        <br>
                        <br>
                    {% endfor %}

                </div>
            </div>

        </div>
    </div>
</div>
</div>


<script>
    //修改密码js
    $('#id_commit').click(function (){
        $.ajax({
            url: '/user/set_password/',
            type: 'post',
            data: {"username": $('#username').val(),
                    "old_password": $('#old_password').val(),
                    "new_password": $('#new_password').val(),
                    "confirm_password": $('#confirm_password').val(),
                    "csrfmiddlewaretoken": '{{ csrf_token }}'
            },
            success: function (args){
                if(args.code === 1000){
                    window.location.reload()
                }else{
                    $('#error').text(args.msg)
                }
            }
        })
    })


</script>
</body>
</html>